{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There are 24 buildings in the testing set.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file</th>\n",
       "      <th>building</th>\n",
       "      <th>site</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>../input/indoor-location-navigation/test//00ff...</td>\n",
       "      <td>5da1389e4db8ce0c98bd0547</td>\n",
       "      <td>SiteName:和达城商场</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>../input/indoor-location-navigation/test//01c4...</td>\n",
       "      <td>5da138b74db8ce0c98bd4774</td>\n",
       "      <td>SiteName:万象城</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>../input/indoor-location-navigation/test//030b...</td>\n",
       "      <td>5da138764db8ce0c98bcaa46</td>\n",
       "      <td>SiteName:银泰百货</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>../input/indoor-location-navigation/test//0389...</td>\n",
       "      <td>5dbc1d84c1eb61796cf7c010</td>\n",
       "      <td>SiteName:杭州大悦城</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>../input/indoor-location-navigation/test//0402...</td>\n",
       "      <td>5da1383b4db8ce0c98bc11ab</td>\n",
       "      <td>SiteName:永旺梦乐城</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                file  \\\n",
       "0  ../input/indoor-location-navigation/test//00ff...   \n",
       "1  ../input/indoor-location-navigation/test//01c4...   \n",
       "2  ../input/indoor-location-navigation/test//030b...   \n",
       "3  ../input/indoor-location-navigation/test//0389...   \n",
       "4  ../input/indoor-location-navigation/test//0402...   \n",
       "\n",
       "                   building            site  \n",
       "0  5da1389e4db8ce0c98bd0547  SiteName:和达城商场  \n",
       "1  5da138b74db8ce0c98bd4774    SiteName:万象城  \n",
       "2  5da138764db8ce0c98bcaa46   SiteName:银泰百货  \n",
       "3  5dbc1d84c1eb61796cf7c010  SiteName:杭州大悦城  \n",
       "4  5da1383b4db8ce0c98bc11ab  SiteName:永旺梦乐城  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "\n",
    "# Input data files are available in the read-only \"../input/\" directory\n",
    "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
    "\n",
    "import os\n",
    "# Prepare paths:\n",
    "import glob\n",
    "from pathlib import Path\n",
    "inpath = '../input/indoor-location-navigation/'\n",
    "metapath = inpath + 'metadata/'\n",
    "trainpath = inpath + 'train/'\n",
    "testpath = inpath + 'test/'\n",
    "\n",
    "# Extract testing files, buildings and sites:\n",
    "os.system(f'grep SiteID {testpath}/* > test_buildings.txt' )\n",
    "test_buildings = pd.read_csv('test_buildings.txt',sep='\\t',header=None,names=['file','building','site'])\n",
    "test_buildings['file'] = test_buildings['file'].apply(lambda x: x[:-2])\n",
    "test_buildings['building'] = test_buildings['building'].apply(lambda x: x[7:])\n",
    "\n",
    "# How many buildings in the testing set?\n",
    "buildings = np.unique(test_buildings['building'])\n",
    "print('There are',len(buildings),'buildings in the testing set.')\n",
    "\n",
    "test_buildings.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Compile C++ pre-processing code:\n",
    "er=os.system(\"g++ ../input/indoor-cpp/1_preprocess.cpp -std=c++11 -o preprocess\")\n",
    "if(er): print(\"Error\")\n",
    "\n",
    "# Reformat the testing set:\n",
    "os.system('mkdir test')\n",
    "for i,(path_filename,building) in enumerate(zip(test_buildings['file'],test_buildings['building'])):\n",
    "    er=os.system(f'./preprocess {path_filename} test {building} {0}') #since we do not know the floor, I put 0.\n",
    "    if(er): print(\"Error:\",path_filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Acceleration, magnetic and orientation testing data:\n",
    "os.system('mkdir indoor_testing_accel')\n",
    "os.system(\"g++ ../input/indoor-cpp/2_preprocess_accel.cpp -std=c++11 -o preprocess_accel\")\n",
    "for building in buildings:\n",
    "    os.system(f'./preprocess_accel {building}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Wifi testing data:\n",
    "os.system('mkdir test_wifi')\n",
    "os.system(\"g++ /kaggle/input/indoor-cpp/2_preprocess_wifi.cpp -std=c++11 -o preprocess_wifi\")\n",
    "for building in buildings:\n",
    "    os.system(f'./preprocess_wifi {building}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
